home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.lib.semantic_lens;
- import sub_arctic.lib.nametag_sem_draw;
- import sub_arctic.input.click_tracking;
- import sub_arctic.input.event;
-
- import java.awt.Point;
- import java.awt.Dimension;
- import java.awt.Rectangle;
-
- /**
- * This class is a special subclass of top_level that provides support for
- * a semantic_lens object providing debugging information about the
- * interactors installed under it. To support a semantic lens it does
- * extra damage declarations similar to those done by semantic_lens_parent.<p>
- *
- * The lens is initially disabled (debugging turned off) and can be brought
- * up (and removed) by a mouse click with certain modifier keys held down
- * (this defaults to control-shift, but can be reset). When debugging_mode
- * is turned on this object works by forcing its last child to be a semantic
- * lens (the configure() for this object moves the lens to be last if it is
- * not already last). The semantic lens does a debug output traversal that
- * displays information about each interactor that it is over.<p>
- *
- * This top_level is typically used with a fake_top_level child to keep
- * subtrees from being disturbed by the addition of the lens as the last
- * child (this can wreck layout constraints). This is done in
- * debug_interactor_applet, for example.<p>
- *
- * @see sub_arctic.lib.semantic_lens_parent
- * @see sub_arctic.lib.semantic
- * @see sub_arctic.lib.debug_interactor_applet
- * @author Scott Hudson
- */
- public class debug_lens_top_level extends top_level implements click_tracking
- {
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a debug_lens_top_level object with know x,y, width and height.
- *
- * @param int x_v the x coordinate of this interactor (should be zero
- * unless you want this interactor to not cover all of its
- * hosting AWT parent).
- * @param int y_v the y coordinate of this interactor (should be zero
- * unless you want this interactor to not cover all of its
- * hosting AWT parent).
- * @param int w_v the width of this top_level (this is also tied to the
- * size of the AWT component).
- * @param int h_v the height of this top_level (this is also tied to the
- * size of the AWT component).
- */
- public debug_lens_top_level(int x_v, int y_v, int w_v, int h_v)
- {
- /* let super class to its work */
- super(x_v,y_v,w_v,h_v);
-
- /* create lens object and arrange for us to hear about all mouse button
- * presses */
- setup_lens();
- manager.click_tracker.add_to_focus(this,null,null);
-
- /* start out of debug mode */
- _debugging = false;
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a debug_lens_top_level and give it default values for x,y,
- * width and height. We assume that the system will fill in these values
- * later.
- */
- public debug_lens_top_level()
- {
- this(0,0,0,0);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Catch damage from children and expand it to include damage from
- * our lens if it overlaps any of that damage. We need to do this
- * because drawing in a lens is not limited to the bound of the object
- * that created it (but is limited to the lens).
- *
- * @param Point top_left top-left corner of child's damage area (in our
- * coordinate system)
- * @param Dimension sz size of the damage area.
- */
- public void damage_from_child(Point top_left, Dimension sz)
- {
- Rectangle damage;
-
- /* let the super class to child damage itself */
- super.damage_self(top_left, sz);
-
- /* if we are not debugging that's it */
- if (!debugging()) return;
-
- /* expand damage to include our whole lens if it overlaps any of
- * the damage from the child. */
- damage = new Rectangle(top_left, sz);
- if (_debug_lens.bound().intersects(damage))
- damage_self(_debug_lens.pos(), _debug_lens.size());
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Are we currently showing the debug lens? */
- protected boolean _debugging = false;
-
- /** Are we currently showing the debug lens? */
- public boolean debugging() {return _debugging;}
-
- /** Programmatically turn debugging lens on or off */
- public void set_debugging(boolean setting)
- {
- /* only do something if this is a change */
- if (setting != _debugging)
- {
- /* set the new value */
- _debugging = setting;
-
- /* if we are going on, put the lens in, otherwise take it out */
- if (setting)
- add_child(_debug_lens);
- else
- remove_child(_debug_lens);
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The debugging lens object. When we are in debugging mode, this will
- * be installed and maintained as our last child. Otherwise, it is
- * unrooted, and just hangs here.
- */
- protected semantic_lens _debug_lens = null;
-
- /** Initialize the debug lens */
- protected void setup_lens()
- {
- int lw, lh;
-
- /* figure out a size for the lens that fits, starting from 200, 200 */
- lw = Math.min(200,w()-10);
- lh = Math.min(200,w()-10);
- if (lw < 0) lw = 10;
- if (lh < 0) lh = 10;
-
- /* build semantic lens object */
- _debug_lens = new semantic_lens(10,10, lw, lh, new nametag_sem_draw(),
- false, "Interactor-Scope", null,
- null, nametag_sem_draw.id);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Override configure to force our lens child to be last (when enabled) */
- public void configure()
- {
- /* if we are debugging, force our lens to be the last child */
- if (debugging())
- {
- if (_debug_lens.child_index() != num_children()-1){
- _debug_lens.move_to_top();
- }
- }
-
- /* set super class to the rest */
- super.configure();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The set of modifier keys that must be down for a mouse button press
- * to toggle debugging mode on/off. This will be some combination of
- * event.ALT_MASK, event.CTRL_MASK, event.META_MASK, and event.SHIFT_MASK
- * ORed together. This defaults to event.SHIFT_MASK | event.CTRL_MASK.
- */
- protected int _signal_modifiers = event.SHIFT_MASK | event.CTRL_MASK;
-
- /**
- * The set of modifier keys that must be down for a mouse button press
- * to toggle debugging mode on/off. This will be some combination of
- * event.ALT_MASK, event.CTRL_MASK, event.META_MASK, and event.SHIFT_MASK
- * ORed together. This defaults to event.SHIFT_MASK | event.CTRL_MASK.
- *
- * @return int the modifiers required to toggle the lens.
- */
- public int signal_modifiers() {return _signal_modifiers;}
-
- /**
- * Change the set of modifier keys that must be down for a mouse button
- * press to toggle debugging mode on/off. The new value must be some
- * combination of event.ALT_MASK, event.CTRL_MASK, event.META_MASK, and
- * event.SHIFT_MASK ORed together.
- *
- * @param int msk the modifiers required to toggle the lens.
- */
- public void set_signal_modifiers(int msk)
- {_signal_modifiers = msk;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Listen for mouse button press input somewhere in the interface. We are
- * only interested mouse down events in the case that all the required
- * modifier keys are held down (and that occured inside us, not somewhere
- * else). In that case we toggle debugging mode (but still do not
- * consume the event).
- *
- * @see sub_arctic.input.click_tracking
- * @param event evt the click event we receive.
- * @param Object user_info (ignored here).
- */
- public boolean track_click(event evt, Object user_info)
- {
- if (evt.root_interactor() == this &&
- evt.id() == event.MOUSE_DOWN &&
- (evt.modifiers() & signal_modifiers()) == signal_modifiers())
- set_debugging(!debugging());
-
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-